import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';

//RenderObjectWithChildMixin管理了一个单独的child
class PullTest extends RenderSliver with RenderObjectWithChildMixin<RenderBox> {

  PullTest({RenderBox? child}){
    this.child = child;
  }

  @override
  void performLayout() {
    geometry = SliverGeometry(
      scrollExtent: 100,
      paintOrigin: 0,
      //paintExtent 开始绘制时相对父布局的位置
      paintExtent: 50,
      maxPaintExtent: 60,
      //剩余可滑动距离
      layoutExtent: 40,
    );

    child?.layout(
      constraints.asBoxConstraints(
        maxExtent: 60
            // Plus only the overscrolled portion immediately preceding this
            // sliver.

            ,
      ),
      parentUsesSize: true,
    );
  }

  @override
  void paint(PaintingContext context, Offset offset) {
    context.paintChild(this.child!, offset);
  }

}


class SinglePullTest extends SingleChildRenderObjectWidget{
  SinglePullTest({super.key,Widget? super.child});
  @override
  RenderObject createRenderObject(BuildContext context) {
    return PullTest();
  }

  @override
  void updateRenderObject(BuildContext context, covariant RenderObject renderObject) {
    super.updateRenderObject(context, renderObject);
  }
}

/// 如果想要外部调用某些方法，可以使用key，但这个key必须是StatefulWidget，所以再包一层

class SinglePullWidget extends StatefulWidget{
  SinglePullWidget({super.key});
  @override
  State<StatefulWidget> createState() => SinglePullState();
}
class SinglePullState extends State<SinglePullWidget>{
  @override
  Widget build(BuildContext context) {
    return SinglePullTest();
  }

}
